package com.situ.crm.controller;

import com.situ.crm.pojo.entity.Permission;
import com.situ.crm.service.IPermissionService;
import com.situ.crm.util.JSONResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

@Api(value = "权限管理", tags = "权限管理模块接口详情")
@RequestMapping("/permission")
@Controller
public class PermissionController {
	@Autowired
	private IPermissionService permissionService;

	@ApiIgnore
	@RequestMapping("/getPermissionPage")
	public String getPermissionPage() {
		return "/permission/permission_list";
	}


	@ApiOperation(value = "分页查询接口", notes = "根据分页信息查询指定页信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "第几页", required = false, defaultValue = "1"),
			@ApiImplicitParam(name = "limit", value = "每页多少条数据", required = false, defaultValue = "5"),
			@ApiImplicitParam(name = "permission", value = "封装搜索条件", required = false),
	})
	@RequestMapping(value = "/selectByPage")
	@ResponseBody
	public JSONResult selectByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer limit, Permission permission) {
		JSONResult jsonResult = permissionService.selectByPage(page, limit, permission);
		return jsonResult;
	}

	@ApiOperation(value = "删除接口", notes = "根据id删除权限的接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "要删除的权限id", required = true)
	})
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	@ResponseBody
	public JSONResult deleteById(Integer id) {
		boolean isSuccess = permissionService.deleteById(id);
		return  isSuccess ?  JSONResult.ok("删除成功") : JSONResult.error("删除失败");
	}

    @ApiIgnore
	@RequestMapping("/deleteAll")
	@ResponseBody
	public JSONResult deleteAll(String ids) {
		boolean isSuccess = permissionService.deleteAll(ids);
		return  isSuccess ?  JSONResult.ok("删除成功") : JSONResult.error("删除失败");
	}

    @ApiIgnore
	@RequestMapping("/getAddPage")
	public String getAddPage() {
		return "/permission/permission_add";
	}

    @ApiIgnore
	@RequestMapping(name = "/add", method = RequestMethod.POST)
	@ResponseBody
	public JSONResult add(Permission permission) {
		boolean isSuccess =  permissionService.add(permission);
		return  isSuccess ?  JSONResult.ok("添加成功") : JSONResult.error("添加失败");
	}


    @ApiIgnore
	@RequestMapping("/selectAllPermisssions")
	@ResponseBody
	public JSONResult selectAllPermisssions() {
		return permissionService.selectAllPermisssions();
	}
}
